package com.geoboard.Fragments;

import com.geoboard.FragInterCommunication;
import com.geoboard.FragInterCommunication.State;
import com.google.android.gms.maps.SupportMapFragment;
import com.locoboard.R;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class BrowseBoardFrag extends Fragment{

	/**** Callback Methods *********************************/
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
		
		
		return inflater.inflate(R.layout.frag_browse_board, container, false);
		
	}
	
	@Override
	public void onAttach(Activity activity){
		super.onAttach(activity);
	}
	
	@Override
	public void onActivityCreated (Bundle savedInstanceState){
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onViewStateRestored (Bundle savedInstanceState){
		super.onViewStateRestored(savedInstanceState);
	}
	
	@Override
	public void onStart(){
		super.onStart();
	}
	
	@Override
	public void onResume(){
		super.onResume();
		((FragInterCommunication)getActivity()).setCurrentState(State.BOARD_MAP);
		
		SupportMapFragment mapFragment = ((FragInterCommunication)getActivity()).getMapFrag();
		
		FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.map_posts_container,mapFragment);
		
		//ft.addToBackStack("maps_board");
		
		ft.commit();
		
		// add the map
		/*SupportMapFragment mapFragment = ((FragInterCommunication)getActivity()).getMapFrag();
		getActivity().getSupportFragmentManager().beginTransaction().
								add(R.id.map_boards_container,mapFragment).commit();*/
	}
	
	@Override
	public void onPause(){
		super.onPause();
		//getActivity().getSupportFragmentManager().popBackStack("maps_board", 0);
		
		
		// remove the map
		SupportMapFragment mapFragment = ((FragInterCommunication)getActivity()).getMapFrag();
		getActivity().getSupportFragmentManager().beginTransaction().remove(mapFragment).commit();
	}
	
	@Override
	public void onStop(){
		super.onStop();
	}
	
	@Override
	public void onDestroyView(){
		super.onDestroyView();
		
		SupportMapFragment mapFragment = ((FragInterCommunication)getActivity()).getMapFrag();
		getActivity().getSupportFragmentManager().beginTransaction().remove(mapFragment).commit();
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
	}
	
	@Override 
	public void onDetach(){
		super.onDetach();
	}

}
